import axios from 'axios';
import { Loading } from 'element-ui';
const service = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境
    // easy-mock服务挂了，暂时不使用了
    baseURL: '/api',
    timeout: 5000
});

service.interceptors.request.use(
    config => {
        config.headers['token'] = '' //token值
        Loading.service({
            lock: true,
            text: 'Loading',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
        });
        return config;
    },
    error => {
        // console.log(error);
        return Promise.reject(error);
    }
);

service.interceptors.response.use(
    response => {
        Loading.service().close()
        if (response.status === 200) {
            return response.data;
        } else {
            return response;
        }
    },
    error => {
        Loading.service().close()
        // console.log(error);
        return Promise.reject(error);
    }
);

export default service;
